-
Notifications
You must be signed in to change notification settings - Fork 328
FIX: MouseDownEvent is triggered when changing from Scene view to Game view (ISXB-1671) #2234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
FIX: MouseDownEvent is triggered when changing from Scene view to Game view (ISXB-1671) #2234
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## develop #2234 +/- ##
===========================================
+ Coverage 68.14% 76.73% +8.59%
===========================================
Files 367 465 +98
Lines 53685 88021 +34336
===========================================
+ Hits 36584 67545 +30961
- Misses 17101 20476 +3375 Flags with carried forward coverage won't be shown. Click here to find out more.
... and 97 files with indirect coverage changes 🚀 New features to boost your workflow:
|
dc01440 to
f21ad55
Compare
f21ad55 to
6157498
Compare
It's tested against all background behavior settings.
The goal is here is to make those conditions self contained in "chunks" so that we can slightly reduce the cognitive load when reading through the OnUpdate() function. This is a personal preference and others in the team might disagree with these changes.
| } | ||
|
|
||
| [Test] | ||
| [Category("Actions")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to add a InputForUI specific test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am hesitant introducing such a big change in the InputManager, also looking at it I wonder:
Isn't the wrong event the mousePosition sent from DeviceSync? Since the event before should not cause the MouseDown, but the second event (caused by the DeviceSync). Or did I get that wrong?
The wrong event is the one before the DeviceSync. That's why we should discard it and not process it.
I don't see it as a big change but maybe the small refactoring is "polluting" the PR in that sense? If you look at 6157498 there are a bit smaller changes and I just factored out some methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit difficult at the moment to judge what is refactoring and what is bug fixing / change in behavior on this PR. I will come back with additional comments once I have realised this.
@ekcoh could you try looking at 6157498 first, since it has the least amount of changes? Let me know if it's better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting for now since the PR states it will add more tests and I added some suggestions. Generally I believe this is an improvement and happy to see some refactoring happening on InputManager. Regarding the refactor I would just like to make sure we have test coverage on the conditions before and after to avoid regressing something. It looked quite similar though and I couldn't spot any mistake there.
My other concern is regarding whether the focus change callback is direct or indirect. If direct it may lead to out-of-order processing of focus change and events which is why I have mentioned previously that we should have our focus changes in the event queue to make it trivial to reason about. If indirect we have a problem since we do not have the focus events true timestamp. Getting a timestamp when the callback is invoked doesn't need to imply that its the true timestamp of the event on the event timeline.
| var mousePointAction = new InputAction(binding: "<Mouse>/position", type: InputActionType.PassThrough); | ||
| mousePointAction.Enable(); | ||
|
|
||
| using (var trace = new InputActionTrace(mousePointAction)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend letting the time step parameter also be an input parameter to the test case. It should still be valid for timeStep = 0.0f, since our logic need to handle event order as the determining factor when time isn't sufficient to tell them apart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would recommend adding that test as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, this would not work. Time needs to move; otherwise, we can't know what events have occurred before and after the focus. This solution relies on event timestamps. Similar to what we do for transitions between Edit Mode and Entering Play Mode, see the conditions in ShouldDiscardEditModeTransitionEvent(). Let me know if I'm missing something.
In theory, if we had focus events in the queues, we wouldn't need to know about timestamps. However, as we discussed, there is a higher risk in introducing such a change. We should still conduct an exploration of the implementation, but I would prefer to land first a less risky solution for this particular bug.
I'm pappy to prototype a solution together if you like, after this fix. We can sync on Slack.
| private bool m_NativeBeforeUpdateHooked; | ||
| private bool m_HaveDevicesWithStateCallbackReceivers; | ||
| private bool m_HasFocus; | ||
| private bool m_DiscardOutOfFocusEvents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a corner case, but what happens with these if there is a domain reload while in playmode? Will they be reinitialised to the same values they had before the domain reload was initiated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, good question. How can I trigger a domain reload in play mode so I can test that?
|
@jfreire-unity Please update this branch with changes from develop to get critical CI fix from #2260. I do not dare updating it for you since the branch has conflicts. |
05cf85f to
6fb0bb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue still occurs for me if I switch the resolution from free aspect to one of the predefined ones.
https://github.com/user-attachments/assets/9a530010-e9cb-432c-9c9a-b047a3a0b4e6
I can't access that image |
|
Just chiming in to bring back a point that was mentioned in our early discussions about this issue. In an ideal world, we'd have to be able to click inside the GameView directly and have the first click that happened before we changed focus be processed as though it had been a normal click after focus. Most software allow that, where you change your window focus and at the same time you click a button from the other window. In that case, if the coordinates of the click (as expressed in the new focused window) are valid, we should accept the click. I don't know how computing new coordinates after the fact is feasible in general though. |
Description
Proposed solution to fix ISXB-1671.
The bug reports a UITK event that shouldn't be triggered. This ocurrs due to a
InputSystemProviderUI Click action being performed once the Editor is in play-mode and we select Game view tab when previously in Scene View.The action that is triggered provides the wrong mouse position. Essentially, an action is being performed for the mouse click/position that happened while out of focus in the Editor and triggered the focus regain. However, when
InputManager.OnUpdate()is called, it assumes the game already is in focus, so there was no way to know if an event was triggered out of focus or not.The proposed solution is to filter and discard the events that happened immediately before focus was regained, by checking if they were received before the focus regain. In the diagram below, essentially we are discarding the "ofending" event - in red - that triggered an Input Action, which would then dispatch a UITK event through
InputSystemProvider.Unrelated changes to bug-fix
I also did a small refactoring to put some conditions in their own functions so that can be easier to read through
InputManager.OnUpdate. This is just a personal preference as it has been historically complicated to reason about all the conditions we have. This is still not perfect, but I hope it's a small improvement for others as well.If you want, you can have a look of the commit which contains the fix changes, 6157498. This doesn't have any refactoring yet and is easier to reason about.
PR template update
Removes a section that we no longer need to take into account.
Testing status & QA
Please describe the testing already done by you and what testing you request/recommend QA to execute. If you used or created any testing project please link them here too for QA.
Overall Product Risks
Comments to reviewers
Verify that the original bug doesn't happen anymore, both on Win and macOS.
Do some other tests with changing Background settings, to make sure nothing has regressed. We can likely use on of the Mouse Visualisers for it.
Checklist
Before review:
Changed,Fixed,Addedsections.Area_CanDoX,Area_CanDoX_EvenIfYIsTheCase,Area_WhenIDoX_AndYHappens_ThisIsTheResult.During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.